package com.yulebaby.callsenter.http.callback;


import com.google.gson.internal.$Gson$Types;
import com.orhanobut.logger.Logger;
import com.yulebaby.callsenter.utils.ToastUtil;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Author: Zhangbo
 * Time: 2016/11/8
 */
public abstract class HttpCallback<T> implements CallBackInterface<T> {

    public Type type;


    public HttpCallback() {
        type = getSuperclassTypeParameter(getClass());
    }

    static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }

    @Override
    public void onSuccess(T result) {
    }

    @Override
    public void onFail(String exception) {
        ToastUtil.showToastLong("服务器异常,请联系产品经理郑重:)");
    }

    public void onFailParam(String info) {
    }

    /**
     * 返回的结果为空
     */
    public void onSuccessResultNull() {}
}
